//
//  HZSearchTextField.m
//  app
//
//  Created by 刘华舟 on 15/5/19.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZSearchTextField.h"

#import "HZImageSourceConstant.h"

static const CGFloat kMallHomeLabelHeight = 30;

@implementation HZSearchTextField

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kImageMallHomeSearch]];
        imageView.frame = CGRectOf([self.ubo fx:UB_LEFT fy:UB_TOP],
                                   [self.ubo ow:kMallHomeLabelHeight oh:kMallHomeLabelHeight]);
        imageView.contentMode = UIViewContentModeCenter;
        self.leftView = imageView;
        self.leftViewMode = UITextFieldViewModeAlways;
       
        
        //voiceBtn
       self.voiceBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.ubo fx:0 fy:UB_TOP],
                                                                 [self.ubo ow:kMallHomeLabelHeight oh:kMallHomeLabelHeight])];
        [self.voiceBtn setImage:[UIImage imageNamed:kImageMallHomeVoice] forState:UIControlStateNormal];
        self.voiceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [self.voiceBtn addTarget:self action:@selector(voiceBtnOnClick) forControlEvents:UIControlEventTouchDown];
        self.rightView = self.voiceBtn;
        self.rightViewMode = UITextFieldViewModeUnlessEditing;
    }
    return self;
}


- (void)voiceBtnOnClick{
    
    if(self.searchDelegate && [self.searchDelegate respondsToSelector:@selector(voiceOnClickSearchTextField)]){
        [self.searchDelegate voiceOnClickSearchTextField];
    }
}


@end
